﻿#include "widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    initWidget();
}

Widget::~Widget()
{
}

//刷新图片
void Widget::refImg()
{
    num++;
    if(num>5)num=1;
    pm->load(":/img/img/img_0"+QString::number(num)+".png");
    labImg->setPixmap(*pm);
}

//初始化
void Widget::initWidget()
{
    this->setMinimumWidth(800);
    this->setMinimumHeight(400);
    //开始布局
    vBox=new QVBoxLayout(this);
    labImg=new QLabel();
    //设置边框
    labImg->setStyleSheet("border:1px solid red");
    labImg->setMaximumSize(600,200);
    labImg->setScaledContents(true);
    vBox->addWidget(labImg);

    labLink=new QLabel();
    labLink->setText("<a href='http://localhost'>打开链接</a>");
    labLink->setOpenExternalLinks(true);
    vBox->addWidget(labLink);

    //默认加载一张图片
    pm=new QPixmap();
    pm->load(":/img/img/img_01.png");
    labImg->setPixmap(*pm);

    //关联刷新信号和槽
    timer=new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(refImg()));
    timer->start(1000);
}

